package com.piece.file.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.InputStream;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@NoArgsConstructor
@Table(name = "tb_sys_file")
@ApiModel(value = "文件表: tb_sys_file")
public class TbSysFile implements Serializable {

    @Id
    @Column(name = "field_id", length = 64)
    @ApiModelProperty(value = "主键")
    private String fileId;

    @Column(name = "business_id", length = 64)
    @ApiModelProperty(value = "业务主键")
    private String businessId;

    @Column(name = "table_name", length = 50)
    @ApiModelProperty(value = "业务表")
    private String table;

    @Column(name = "md5")
    @ApiModelProperty(value = "md5")
    private String md5;

    @Column(name = "server_id")
    @ApiModelProperty(value = "云存储ID")
    private String serverId;

    @Column(name = "server_path")
    @ApiModelProperty(value = "云存储目录")
    private String serverPath;

    @Column(name = "local_path")
    @ApiModelProperty(value = "本地路径")
    private String localPath;

    @Column(name = "original_filename", length = 150)
    @ApiModelProperty(value = "文件原始名称")
    private String originalFilename;

    @Column(name = "server_filename", length = 100)
    @ApiModelProperty(value = "文件存储名称")
    private String serverFileName;

    @Column(name = "content_type", length = 10)
    @ApiModelProperty(value = "文件扩展名")
    private String contentType;

    /**
     * 参考：${@link com.piece.core.framework.enums.FileType}
     */
    @Column(name = "channel", length = 2)
    @ApiModelProperty(value = "文件类别", notes = "1:图片,2:文档,3:音频,4:视频,5:模板,0:其它")
    private String channel;

    @Column(name = "upload_time")
    @ApiModelProperty(value = "上传时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date uploadTime;

    @Column(name = "file_size")
    @ApiModelProperty(value = "文件大小")
    private Long fileSize;

    @Column(name = "duration")
    @ApiModelProperty(value = "文件时长")
    private Long duration;

    @Column(name = "create_by")
    @ApiModelProperty(value = "上传人")
    private String createBy;

    @Transient
    @ApiModelProperty(value = "文件流")
    private InputStream fileInputStream;

    @Transient
    @ApiModelProperty(value = "是否文件夹")
    private boolean isDir;
}
